﻿using System;
using System.Threading.Tasks;
using Abp.UI;

namespace KelonProud.Extensions
{
    public  static class ExceptionHander
    {
        public static void TryCatch(this Action action)
        {
            try
            {
                action();
            }
            catch (Exception exception)
            {
                throw new UserFriendlyException(exception.GetTrueMessage());
            }
        }

        public static object TryCatchReturn(this Func<object> action)
        {
            try
            {
               return action();
            }
            catch (Exception exception)
            {
                throw new UserFriendlyException(exception.GetTrueMessage());
            }
        }

        public static async Task TryCatchAsysc(Func<Task>  action)
        {
            try
            {
              await action();
            }
            catch (Exception exception)
            {
                throw new UserFriendlyException(exception.GetTrueMessage());
            }

        }
    }
}
